package com.android.flickr;

import org.xml.sax.*;
import org.xml.sax.helpers.*;

public class TokenParser extends DefaultHandler
{
	boolean gotTok = false;
	boolean gotFrob = false;
	String token = "NOTHING";
	String frob = "NOTHING";
	
	@Override
	public void startElement(String nsURI, String strippedName,
			String tagName, Attributes attributes) throws SAXException
	{
		System.out.println("Stripped Name: "+strippedName);
		System.out.println("Tagname: "+ tagName);
		if (strippedName.equalsIgnoreCase("token"))
			{
			System.out.println("Found Token");
			gotTok = true;
			}
		else if (strippedName.equalsIgnoreCase("frob"))
		{
			System.out.println("Found FROB");
			gotFrob= true;
		}
	}
	
	@Override
	public void endElement(String nsURI, String strippedName,String tagName)
			throws SAXException {
		System.out.println("End of Stripped Name: "+strippedName);
			if (strippedName.equalsIgnoreCase("token"))
			{
				System.out.println("Found end of token");
				gotTok=false;
			}
			else if (strippedName.equalsIgnoreCase("frob"))
			{
				System.out.println("Found end of FROB");
				gotFrob= false;
			}
	}
	@Override
	public void characters(char[] ch, int start, int length)
	{
		if (gotTok)
		{
			token = new String(ch, start, length);
			System.out.println("Located");
			gotTok = false;
		}
		
		else if (gotFrob)
		{
			frob = new String(ch, start,length);
			System.out.println("Located Frob");
			gotFrob=false;
		}
	}
	
	public String getToken()
	{
		return token;
	}
	
	public String getFrob()
	{
		return frob;
	}

}
